package com.juntuo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import com.juntuo.entity.Device;
import com.juntuo.mapper.DeviceMapper;
import com.juntuo.service.DeviceService;
import com.juntuo.service.ParkService;
import com.juntuo.service.helper.CommonServiceImpl;
import com.juntuo.util.LatLonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 简介：片区 街道 泊位的服务
 * 作者：Jason (chenxj@hadlinks.com)
 * 时间：2018/3/17 16:22
 */
@Service
public class DeviceServiceImpl extends CommonServiceImpl<Device> implements DeviceService {
    @Autowired
    private DeviceMapper deviceMapper;
    @Autowired
    private ParkService parkService;

    @Override
    public void updateByDeviceIdSelective(Device device) {
        deviceMapper.updateByDeviceIdSelective(device);
    }


    @Override
    public PageInfo<Map<String,Object>> findPagedDevice(int pageNum,int pageSize,  String province, String city,String district,String companyName, String parkNumber,String name) {
        PageHelper.startPage(pageNum,pageSize);
        List<Map<String,Object>> devices=deviceMapper.selectByParams(name,province,city,district,companyName,parkNumber);
        PageInfo pageInfo= new PageInfo(devices);
        return pageInfo;
    }


    @Override
    public PageInfo<Map<String,Object>> selectNearByDevices(int pageNum,int pageSize,Double lat,  Double lon,Double distance,int type) {
        PageHelper.startPage(pageNum,pageSize);
        if(null==distance || distance==0){
            distance=0.5;
        }
        Map<String,Double> map =LatLonUtil.getMinAndMaxLatLon(lat, lon,distance);
        Double minlat=map.get("minlat");
        Double maxlat=map.get("maxlat");
        Double minlng=map.get("minlng");
        Double maxlng=map.get("maxlng");
        List<Map<String,Object>> devices=deviceMapper.selectNearByDevices(minlat,maxlat,minlng,maxlng,type);
        PageInfo pageInfo= new PageInfo(devices);
        return pageInfo;
    }
}
